import { ActivityAwardVO } from '@/services/ActivityAwardService'
import { PageParam } from '@/services/common'
import { PosterUpdateDTO, PosterVO } from '@/services/PosterService'
import { covertTableData } from '@/utils/tableUtil'
import { request } from '@umijs/max'

export interface ActivityVO {
  /**
   * id
   */
  id: string
  /**
   * 活动名称
   */
  activityName: string
  /**
   * 活动标题
   */
  activityTitle: string
  /**
   * 粉丝量计算规则
   */
  countValueType: string
  /**
   * 分享标题
   */
  shareTitle: string
  sharePoster: string
  /**
   * 分享封面图
   */
  shareCover: string
  /**
   * 活动开始时间
   */
  startTime: string
  /**
   * 活动结束时间
   */
  endTime: string
  /**
   * 创建时间
   */
  createTime: string
}

export interface ActivityQueryDTO extends PageParam {
  /**
   * id
   */
  id: string
}

export interface ActivityUpdateDTO {
  id?: string
  activityName: string
  activityTitle: string
  countValueType: string
  shareTitle: string
  shareCover: string
  qrPos: string
  bindWpId: string
  sharePoster: string
  bindWaId: string
  startTime: string
  endTime: string
  posterList: PosterUpdateDTO[]
}

export interface ActivityFormBO {
  id?: string
  activityName?: string
  activityTitle?: string
  countValueType?: string
  shareTitle?: string
  shareCover?: string
  qrPos?: string
  bindWpId?: string
  sharePoster?: string
  bindWaId?: string
  startTime?: string
  endTime?: string
  posterList?: PosterUpdateDTO[]
  firstEnter: number
  firstShare: number
  firstSubscribe: number
}

export interface ActivityInfoVO {
  sharePoster: string
  posters: PosterVO[]
  awards: ActivityAwardVO[]
  id: string
  activityName: string
  activityTitle: string
  countValueType: string
  qrPos: string
  bindWpId: string
  bindWaId: string
  shareTitle: string
  shareCover: string
  startTime: Date
  endTime: Date
  createTime: Date
}

export const getActivityById = async (id: string) => {
  return request<ActivityVO>(`/api/activity?id=${id}`, { method: 'GET' })
}

export const getActivityList = async (params: ActivityQueryDTO) => {
  return request<Array<ActivityVO>>(`/api/activity/list`, { method: 'GET', params })
}

export const getActivityPage = async (params: ActivityQueryDTO) => {
  let response = await request<Array<ActivityVO>>(`/api/activity/page`, { method: 'GET', params })
  return covertTableData(response)
}

export const updateActivity = async (activityUpdateDTO: ActivityUpdateDTO) => {
  return request<ActivityVO>(`/api/activity/update`, { method: 'POST', data: activityUpdateDTO })
}

export const saveActivity = async (activityUpdateDTO: ActivityUpdateDTO) => {
  return request<ActivityVO>(`/api/activity/save`, { method: 'POST', data: activityUpdateDTO })
}

export const removeActivity = async (id: string) => {
  return request<boolean>(`/api/activity/remove?id=${id}`, { method: 'POST' })
}

export const getActivityInfo = async (id: string) => {
  return request<ActivityInfoVO>(`/api/activity/getActivityInfo?id=${id}`)
}
